package xyz.fuqufyb.aec.data;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: JosnRusult
 * @date 时间: 2021/1/29 15:04
 */

public class JsonResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 11L;
//    private Integer status;
//
//    private String msg;
//
//    private T result;

    public JsonResult() {
        put("status", 200);
        put("msg", "success");
        put("result", null);
    }

    /**
     * 成功数据
     *
     * @param msg
     * @return
     */
    public static JsonResult getJsonSuccess(String msg) {
        JsonResult jsonResult = new JsonResult();

        jsonResult.put("msg", msg);
        jsonResult.put("result", null);

        return jsonResult;
    }

    public static JsonResult getJsonSuccess(Object result) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.put("result", result);
        return jsonResult;
    }

    /**
     * 成功
     *
     * @param map
     * @return
     */
    public static JsonResult getJsonSuccess(Map<String,Object> map) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.putAll(map);
        return jsonResult;
    }

    /**
     * 失败数据
     *
     * @param msg
     * @return
     */
    public static JsonResult getJsonError(String msg) {
        return getJsonError(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg, null);
    }

    /**
     * 失败
     *
     * @return
     */
    public static JsonResult getJsonError() {
        return getJsonError(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员", null);
    }

    public static JsonResult getJsonError(Integer status, String msg) {
        return getJsonError(status, msg, null);
    }

    public static JsonResult getJsonError(Integer status, String msg, Object result) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.put("status", status);
        jsonResult.put("msg", msg);
        jsonResult.put("result", result);
        return jsonResult;
    }

    @Override
    public Object put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
